package com.wl.eb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.eb.mapper.EbCommentMapper;
import com.wl.eb.module.EbComment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2021/12/6 16:41
 */
@Service//证
public class CommentService {
    @Resource
    private EbCommentMapper ebCommentMapper;
    /**
     * 分页查询评论列表信息
     * @param psize 页数
     * @return
     */
    public Page list(int psize){
        Page page=new Page(psize,5);
        Page commentPage = ebCommentMapper.selectPage(page, new QueryWrapper<EbComment>()
                .orderByDesc("ec_create_time"));
        return commentPage;
    }

    /**
     * 添加留言
     * @param ebComment  待添加 的留言对象
     * @return
     */
    public boolean save(EbComment ebComment){
        //1.为留言添加创建时间
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        ebComment.setEcCreateTime(sdf.format(new Date()));//获取系统时间字符串
        //2.添加留言
        int result = ebCommentMapper.insert(ebComment);
        return result>0?true:false;
    }
}
